﻿Imports TodoMicroSolutionPackV1.dal.dto
Imports NHibernate
Imports NHibernate.Cfg
Imports NHibernate.Criterion
Namespace dal.dao
    Public Class constanteDAO
        Inherits GenericNHibernateDAO(Of constante, Integer)
        Public Function getConstantes(ByVal categoria As String, ByVal tipo As String) As IList(Of constante)
            Dim q As IQuery = session.CreateQuery("from constante c where c.categoria = :categoria and c.tipo = :tipo")
            q.SetString("categoria", categoria)
            q.SetString("tipo", tipo)

            Return q.List(Of constante)()

        End Function

        Public Function buscarConstantes(ByVal categoria As String, ByVal tipo As String) As IList(Of constante)
            Dim criteria As ICriteria = session.CreateCriteria(Of constante)()
            criteria.Add(Expression.Like("categoria", "%" & categoria & "%"))
            criteria.Add(Expression.Like("tipo", "%" & tipo & "%"))

            Return criteria.List(Of constante)
        End Function

        Public Function getUnidadMedida(ByVal codigo As String)
            Dim criteria As ICriteria = session.CreateCriteria(Of constante)()
            criteria.Add(Expression.Eq("categoria", "facturacion"))
            criteria.Add(Expression.Eq("tipo", "unidades_medida"))
            criteria.Add(Expression.Eq("codigo", codigo))

            Return criteria.UniqueResult(Of constante)()
        End Function

        Public Function getTipoEntidad(ByVal codigo As String)
            Dim criteria As ICriteria = session.CreateCriteria(Of constante)()
            criteria.Add(Expression.Eq("categoria", "entidades"))
            criteria.Add(Expression.Eq("tipo", "tipo"))
            criteria.Add(Expression.Eq("codigo", codigo))

            Return criteria.UniqueResult(Of constante)()
        End Function

        Public Function getIva(ByVal codigo As Integer) As constante
            Dim q As IQuery = session.CreateQuery("from constante c where c.categoria = 'facturacion' and c.tipo = 'alicuota_iva' and codigo= :codigo")

            q.SetString("codigo", codigo.ToString)


            'solo deberia contener un unico valor
            Return q.UniqueResult(Of constante)()

        End Function
        Public Sub New(ByRef session As ISession)
            MyBase.New(session)
        End Sub
    End Class
End Namespace
